package com.example.shop.service.impl;

import com.example.shop.mapper.RoleMapper;
import com.example.shop.model.Role;
import com.example.shop.model.User;
import com.example.shop.service.RoleService;
import com.example.shop.utils.PageBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class RoleServiceImpl implements RoleService {
    @Resource
    private RoleMapper roleMapper;

    @Override
    public int updateUserRole(User user) {
        return roleMapper.updateUserRole(user);
    }

    @Override
    public PageBean<Role> getRolePageBean(int pageNo, int pageSize, String search) {
        PageBean<Role> pageBean = new PageBean<>();
        pageBean.setPageSize(pageSize);
        pageBean.setDataCount(roleMapper.dataCount());
        pageBean.setPageNo(pageNo);
        if ("".equals(search) || search.length() == 0) {
            search = null;
        }
        pageBean.setDataList(roleMapper.getRolePageBean((pageNo - 1) * pageSize, pageSize, search));
        return pageBean;
    }
}
